from . import admin
from app.some_func import wapper
from flask import url_for, current_app, jsonify
import json

# 菜单页面
@admin.get('/menu')
@wapper
def menu():
    menu = """
    [
    {
        "href": "/admin/article",
        "icon": "layui-icon layui-icon-read",
        "id": 1,
        "title": "文章管理",
        "type": "1"
    },
    {
        "href": "/admin/category",
        "icon": "layui-icon layui-icon-app",
        "id": 3,
        "title": "分类管理",
        "type": "1"
    },
    {
        "href": "/admin/user",
        "icon": "layui-icon layui-icon-user",
        "id": 7,
        "title": "用户管理",
        "type": "1"
    },
    {
        "href": "/admin/setting",
        "icon": "layui-icon layui-icon-set",
        "id": 8,
        "title": "站点管理",
        "type": "1"
    }
    ]
    """
    return json.loads(menu)
@admin.get('/configs')
@wapper
def configs():
    # 网站配置
    config = dict(logo={
        # 网站名称
        "title": "Pyblog Manager",
        # 网站图标
        "image": "/static/admin/images/logo.png"
        # 菜单配置
    }, menu={
        # 菜单数据来源
        "data": url_for('admin.menu'),
        "collaspe": False,
        # 是否同时只打开一个菜单目录
        "accordion": True,
        "method": "GET",
        # 是否开启多系统菜单模式
        "control": False,
        # 顶部菜单宽度 PX
        "controlWidth": 500,
        # 默认选中的菜单项
        "select": "0",
        # 是否开启异步菜单，false 时 data 属性设置为菜单数据，false 时为 json 文件或后端接口
        "async": True
    }, tab={
        # 是否开启多选项卡
        "enable": True,
        # 切换选项卡时，是否刷新页面状态
        "keepState": False,
        # 是否开启 Tab 记忆
        "session": True,
        # 最大可打开的选项卡数量
        "max": 10,
        "index": {
            # 标识 ID , 建议与菜单项中的 ID 一致
            "id": "10",
            # 页面地址
            "href": url_for('admin.welcome'),
            # 标题
            "title": "首页"
        }
    }, theme={
        # 默认主题色，对应 colors 配置中的 ID 标识
        "defaultColor": "2",
        # 默认的菜单主题 dark-theme 黑 / light-theme 白
        "defaultMenu": "dark-theme",
        # 是否允许用户切换主题，false 时关闭自定义主题面板
        "allowCustom": True
    }, colors=[{
        "id": "1",
        "color": "#2d8cf0"
    },
        {
            "id": "2",
            "color": "#5FB878"
        },
        {
            "id": "3",
            "color": "#1E9FFF"
        }, {
            "id": "4",
            "color": "#FFB800"
        }, {
            "id": "5",
            "color": "darkgray"
        }
    ], links=current_app.config.get("SYSTEM_PANEL_LINKS"), other={
        # 主页动画时长
        "keepLoad": 0,
        # 布局顶部主题
        "autoHead": False
    }, header=False)
    return jsonify(config)